package com.lxy.controller;

import com.lxy.pojo.User;
import com.lxy.service.impl.LoginServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * 请不要模仿我
 *
 * @author lxy
 * @date 2022/9/28 14:52
 * com.lxy.login.controller.
 */
@Controller
@RequestMapping("/user")
public class LoginController {
    @Autowired
    private LoginServiceImpl loginService;
    /*
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    * */
    @RequestMapping("/login")
    public String login(String uname, String pwd, HttpServletRequest req) {
        System.out.println(uname + "     " + pwd);
        User login = loginService.login(uname, pwd);
        if(login!=null){
            req.setAttribute("uname",login.getUname());
            System.out.println("登录成功"+login);
            return "forward:/admin.jsp";
        }else {
            req.setAttribute("msg","用户名或者密码错误！");
            return "forward:/login.jsp";
        }
    }
}
